import qs from 'qs'

const SERVER_PATH = process.env.NUXT_SERVER_PATH
const SERVER_PORT = process.env.NUXT_SERVER_PORT
const BASEURL = SERVER_PATH === 'localhost' ? `http://${SERVER_PATH}:${SERVER_PORT}` : ''

export default $axios => authless => ({
  register (params) {
    return $axios.$post(`${BASEURL}${authless}/register`, qs.stringify(params))
  },

  getCaptcha (params) {
    return $axios.$post(`${BASEURL}${authless}/getsmsCode`, qs.stringify(params))
  },

  forgotPassword (params) {
    return $axios.$post(`${BASEURL}${authless}/forgotPassword`, qs.stringify(params))
  },

  activate (acode) {
    return $axios.$get(`${BASEURL}${authless}/activate?code=` + acode)
  },

  resetCode (acode) {
    return $axios.$get(`${BASEURL}${authless}/resetCode?code=` + acode)
  },

  resetPassword (params) {
    return $axios.$post(`${BASEURL}${authless}/resetPassword`, qs.stringify(params))
  }
})
